import http from '../../../../services/http/index'

let util = require('../../../../utils/index')

Page({
  /**
   * 页面的初始数据
   */
  data: {
    password1: '',
    password2:'',
    code:'',
    areaCode:'',
    mobile:'',
  
    // 确认按钮
    confirmBtn: {
      disabled: true,
    }
  },
  onLoad: function (options) {
    this.setData({
      code:options.code,
      areaCode:options.areaCode,
      mobile:options.mobile
    });
  },

  /**
   * input 输入事件处理函数
   * @param event
   * @returns {void}
   */
  // 判断密码是否为空-好讲下面的的“确定”设为高亮
  handleInputChange({ currentTarget: { dataset: { name } }, detail: { value } }) {
    this.setData({ [name]: value })

    if (this.data.password1 != '' && this.data.password2 != '' && this.data.password1 == this.data.password2) {
      this.setData({
        'confirmBtn.disabled': false
      })
    }
  },
  /**
   * 确认按钮点击处理函数
   * @returns {void}
   */
  handleConfirmBtnTap() {
    var that=this;
    if (this.data.confirmBtn.disabled){
      return;
    } else{
      var form = this.data;
      http.changeForget({
        areaCode: form.areaCode,
        mobile: form.mobile,
        code: form.code,
        pwd:form.password1,
        pwd_confirmation:form.password2
      }).then(data => {
        // 成功后跳到下一个页面
        wx.showToast({
          title: '保存成功',
          icon: 'success',
          duration: 2000
        });
        wx.reLaunch({ url: '../../login/Login'})
      }).catch(function(err){
        wx.showToast({
          title: err.message,
          icon: 'none',
          duration: 2000
        })
      })

    }

  }
})